package com.houger.ddd.redpacket.controller.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.houger.ddd.redpacket.facade.dto.GrabRedPacketDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * @author Houger.
 * @date 2024年04月18日 15:45.
 */
@Builder
@Data
public class GrabRedPacketResVo {
    @Schema(description ="grabRedPacketDtoList")
    private List<GrabRedPacketDto> grabRedPacketDtoList;

    @Schema(description ="redPacketId")
    private String redPacketId;

    private String totalAmount;

    private String totalCount;

    private String residualAmount;

    private String residualCount;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sendTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime burnoutTime;

    private Long  consumingSeconds;

    public void setConsumingSeconds() {
        Optional.ofNullable(this.burnoutTime)
            .ifPresent((e)->{
                Duration duration = Duration.between(this.sendTime, e);
                this.consumingSeconds=duration.getSeconds();
            });
    }

}
